<?php
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DS.'caches_data'.DS);
class kanjia {
	private $db;
	function __construct() {
		$this->db = pc_base::load_model('content_model');
	}

	public function init() {
		$db_jifen_log = pc_base::load_model('jifen_log_model');
		$_userid = param::get_cookie('_userid');
		//echo $_userid;exit();
		if ($_userid==''||!isset($_userid)||$_userid<=0) {
			echo '请先登录';
			exit();
		}
		$id=intval($_POST['id']);
		$con='砍价-'.$id;
		$res = $db_jifen_log->get_one("uid='$_userid' and type=88 and content='$con'",'*','ymd desc');
		//print_r($res);exit();
		if ($res['ymd']==date('Y-m-d',time())) {
			echo '1个账户每天只能砍价1次，想快速获得这个商品吗？快快邀请好友来一起砍价吧！';
			exit();
		}
		$db_shop = pc_base::load_model('shop_model');
        $res = $db_shop->get_one("id='$id'");
        $price_new=$res['price_new'];
        $price_jifen=$res['price_jifen'];
        if ($price_new==0) {
        	$price_new=$price_jifen;
        }
        $price_new=$price_new-5;
        $db_shop->update(['price_new' => $price_new], ['id' => $id]);
        $db_member = pc_base::load_model('member_model');
        $res = $db_member->get_one("userid='$_userid'");
        $jifen=$res['jifen']+5;        
        $db_member->update(['jifen' => $jifen], ['userid' => $_userid]);
        
        $jifeng_log['uid']=$_userid;
		$jifeng_log['price']=5;
		$jifeng_log['type']=88;
		$jifeng_log['content']='砍价-'.$id;
		$jifeng_log['mca']='member::kanjia';
		$jifeng_log['ip']=ip();
		$jifeng_log['ymd']=date('y-m-d',time());
		$jifeng_log['ymdhis']=date('y-m-d H:i:s',time());

        $uid = $db_jifen_log->insert($jifeng_log, 1);

	}
	

}
?>